package com.five.controller;

import com.five.pojo.ClubJoin;
import com.five.pojo.PageBean;
import com.five.pojo.Result;
import com.five.service.ClubJoinService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "申请入团接口")
@RestController
@CrossOrigin
@RequestMapping("/clubJoin")
public class ClubJoinController {

    @Autowired
    ClubJoinService joinService;
    //申请入团
    @Operation(summary = "申请入团(学生)")
    @PostMapping("/add")
    public Result add(@RequestBody ClubJoin clubJoin)
    {
        joinService.addClub(clubJoin);
        return Result.success();
    }

    //查询入团申请信息
    @Operation(summary = "查询入团申请信息(团长)")
    @GetMapping("/getJoinInfo")
    public Result getJoinInfo(){
        List<ClubJoin> list = joinService.getAllJoin();
        return Result.success(list);
    }



    //分页
    @Operation(summary = "按条件查询分页")
    @GetMapping("/page")
    public Result page(@RequestParam(defaultValue = "1") Integer page ,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String cName , String sName)
    {
        PageBean pageBean = joinService.page(page , pageSize , cName , sName);
        return Result.success(pageBean);
    }

    //查看社团申请待审核数量
    @Operation(summary = "查看社团申请待审核数量")
    @GetMapping("/getStatus")
    public Result getStatus(){
        Integer total = joinService.getStatus();
        return Result.success(total);
    }

    //更新状态(团长)
    @Operation(summary = "团长审核学生入团申请")
    @PutMapping("/headerModStatus")
    public Result updateStatus(Integer status , Integer id){
        joinService.updateStatus(status , id);
        if(status == 1){
            return Result.success(1);
        }
        return Result.success(0);
    }

    //根据团长查社团成员
    @Operation(summary = "根据团长查社团成员")
    @GetMapping("/getByHeader")
    public Result getByHeader(String header){
        System.out.println(header);
        List<ClubJoin> studentlist = joinService.getByHeader(header);
        return Result.success(studentlist);
    }

    //根据id删除学生
    @Operation(summary = "根据id删除学生")
    @DeleteMapping
    public Result delete(Integer id){
        joinService.deleteById(id);
        return Result.success();
    }
}
